Skip to content

Conversation

@rbeucher
Copy link
Contributor

Description

Modifies the get_frequency function in ERA5 native6 fix to handle case where monthly-averaged data are stored in single NetCDF file (one file per month) and have thus a time dimension length of 1.

Closes #2511

Link to documentation:


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


To help with the number pull requests:

@rbeucher
Copy link
Contributor Author

Hi @schlunma, @valeriupredoi,

Could someone please take a moment to review this for me? Thanks!

R

@codecov
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

❌ Patch coverage is 91.30435% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.42%. Comparing base (cbb23dc) to head (0b6af74).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
esmvalcore/cmor/_fixes/native6/era5.py 91.30% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2512      +/-   ##
==========================================
- Coverage   95.46%   95.42%   -0.04%     
==========================================
  Files         260      260              
  Lines       15526    15513      -13     
==========================================
- Hits        14822    14804      -18     
- Misses        704      709       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good @rbeucher - and biy did you have to wait for a review - sorry 🍺 @schlunma @sloosvel maybe we can squeeze this one in 2.12?

Copy link
Contributor

@schlunma schlunma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently breaks support for daily ERA5 data that has been added in #2178.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2025

In order to maintain a backlog of relevant pull requests, we automatically label them as stale after 180 days of inactivity.

If this pull request is still important to you, please comment below to remove the stale label. Otherwise, this pull request will be automatically closed in 60 days. If this pull request only suffers from a lack of reviewers, please tag the @ESMValGroup/technical-lead-development-team so they can help you find a suitable reviewer.

@github-actions github-actions bot added the Stale label Sep 2, 2025
@flicj191
Copy link
Contributor

I will look into this again to fix the single monthly files

@github-actions github-actions bot removed the Stale label Sep 16, 2025
@flicj191
Copy link
Contributor

@schlunma @valeriupredoi @ESMValGroup/esmvaltool-developmentteam
Can we get this re-checked please?
FYI @rbeucher

@bouweandela
Copy link
Member

We discussed this feature in the associated issue, and there I suggested #2511 (comment). Does that not work?

@flicj191
Copy link
Contributor

flicj191 commented Sep 17, 2025

We discussed this feature in the associated issue, and there I suggested #2511 (comment). Does that not work?

Ah I missed that sorry, I'll test it out and found that it still runs the get_frequency each time for class AllVars here:

self._fix_monthly_time_coord(cube)

def _fix_monthly_time_coord(cube):
"""Set the monthly time coordinates to the middle of the month."""
if get_frequency(cube) == "monthly":

I can change this part in this PR

@flicj191
Copy link
Contributor

@bouweandela I've updated, let me know what you think. thanks!

Copy link
Member

@bouweandela bouweandela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine now. I wonder if we could completely get rid of the get_frequency function?

It would be nice to add a unit test, could you do that?

def _fix_monthly_time_coord(cube, frequency):
"""Set the monthly time coordinates to the middle of the month."""
if get_frequency(cube) == "monthly":
if frequency in ("monthly", "mon", "mo"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "mo" is not needed, as it looks like monthly frequency will be either "monthly" as returned by the get_frequency function or "mon" from the CMOR table:

"frequency":{
"1hr":"sampled hourly",
"1hrCM":"monthly-mean diurnal cycle resolving each day into 1-hour means",
"1hrPt":"sampled hourly, at specified time point within an hour",
"3hr":"sampled every 3 hours",
"3hrPt":"sampled 3 hourly, at specified time point within the time period",
"6hr":"sampled every 6 hours",
"6hrPt":"sampled 6 hourly, at specified time point within the time period",
"day":"daily mean samples",
"dec":"decadal mean samples",
"fx":"fixed (time invariant) field",
"mon":"monthly mean samples",
"monC":"monthly climatology computed from monthly mean samples",
"monPt":"sampled monthly, at specified time point within the time period",
"subhrPt":"sampled sub-hourly, at specified time point within an hour",
"yr":"annual mean samples",
"yrPt":"sampled yearly, at specified time point within the time period"
},

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bouweandela, I'm not sure I can speak to the get_frequency function.. it was added for some use cases?
I have added a test for "mon" frequency repeating one for "monthly"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a test for "mon" frequency repeating one for "monthly"

Great!

Thanks @bouweandela, I'm not sure I can speak to the get_frequency function.. it was added for some use cases?

It was added before we passed all the facets and their values from the recipe to the fix functions. I've thought about it some more, and it can be removed. In rare cases where the frequency is wrongly inferred from the mip, the user can specify the right frequency value in the recipe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok, should I create a new issue/PR to discuss specifically or I can just change here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just change it here

Copy link
Contributor

@flicj191 flicj191 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing get_frequency I had to parse the frequency to fix_hourly_time_coordinate and fix_accumulated_units which I think works, similar to _fix_monthly_time_coord but the tests are failing, not sure what i'm missing? the fixes aren't applied? @bouweandela

@flicj191
Copy link
Contributor

flicj191 commented Oct 7, 2025

I have reverted the changes of removing the get_frequency function, more testing was showing that it wasn't working if frequency wasn't defined first in the dataset which doesn't seem to be common practise so would still be useful to have.

@bouweandela
Copy link
Member

@flicj191 In #2855 I've changed the test so it is more realistic and you can see that a frequency keyword argument is now always supplied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

ERA5 Native6 Fix cannot handle single monthly-averaged files

5 participants